package com.gscitysfy.cus.drain.config;

import com.gscitysfy.cus.drain.constants.RedisKeyConstant;
import com.gscitysfy.cus.drain.utils.RedisUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author 葛守跃
 * @version 1.0.0
 * @ClassName DisposableHandle
 * @Description 系统退出前，需要执行的操作
 * @creatTime 2022/8/2 15:04
 */
@Component
@Slf4j
@Order(1)
public class DisposableHandle implements CommandLineRunner {

    @Resource
    private RedisUtil redisUtil;

    /**
     * 清除字典缓存
     */
    public void clearDictBuffer() throws InterruptedException {
        redisUtil.delFuzzyKey(RedisKeyConstant.DATA_DICT_KEY + "*");
    }

    @Override
    public void run(String... args) throws Exception {
        this.clearDictBuffer();
    }
}
